var t = require;
var e = module;
var o = exports;
var a,
    i =
        (this && this.__extends) ||
        ((a = function (t, e) {
            return (a =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (t, e) {
                        t.__proto__ = e;
                    }) ||
                function (t, e) {
                    for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
                })(t, e);
        }),
        function (t, e) {
            a(t, e);
            function o() {
                this.constructor = t;
            }
            t.prototype = null === e ? Object.create(e) : ((o.prototype = e.prototype), new o());
        }),
    n =
        (this && this.__decorate) ||
        function (t, e, o, a) {
            var i,
                n = arguments.length,
                r = n < 3 ? e : null === a ? (a = Object.getOwnPropertyDescriptor(e, o)) : a;
            if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, a);
            else
                for (var s = t.length - 1; s >= 0; s--)
                    (i = t[s]) && (r = (n < 3 ? i(r) : n > 3 ? i(e, o, r) : i(e, o)) || r);
            return n > 3 && r && Object.defineProperty(e, o, r), r;
        };
Object.defineProperty(o, "__esModule", {value: !0});
var r = t("UIBase"),
    s = t("UIConfig"),
    c = t("UIManager"),
    p = t("BoxItem"),
    l = cc._decorator,
    d = l.ccclass,
    u =
        (l.property,
        l.menu,
        (function (t) {
            i(e, t);
            function e() {
                var e = (null !== t && t.apply(this, arguments)) || this;
                e.selSkillItem = 1;
                e.tag = "UIMerge";
                e.looperNode = [];
                e.selList = [];
                e.setCanClickNodeList = [];
                e.merageId = "";
                e.canClick = !1;
                e.merageData = {};
                e.tempViewList = [];
                return e;
            }
            e.prototype.onShowEnd = function () {
                EVUIEffView.on(EVUIEffView.clickBoxItem, this.clickItem.bind(this), this);
                this.updateViewMergeData();
                this.updateView();
            };
            e.prototype.updateViewMergeData = function () {
                this.merageData = CacheDataManager.getMerageObj();
            };
            e.prototype.clickItem = function (t, e, o, a, i) {
                if (e == this.tag && !i) {
                    if (0 == this.selList.length) {
                        var n = this.getMerageKey(o);
                        this.merageId = n;
                    }
                    if (this.merageId) {
                        var r = this.selList.indexOf(o);
                        r >= 0 ? this.selList.splice(r, 1) : this.selList.push(o);
                        this.updateView();
                    }
                }
            };
            e.prototype.setCheckList = function (t) {
                var e = !0;
                this.setCanClickNodeList.length = 0;
                var o = GameDataValue.getAllSelfEquip(),
                    a = CacheDataManager.getCostumeup(),
                    i = CacheDataManager.getCostume(),
                    n = a[t];
                if (n) {
                    var r = i[n.costume_id].type,
                        s = this.getQualityList(n.up_quality ? n.up_quality + "" : ""),
                        c = (n.up_costume + "").split("|"),
                        p = n.up_quality ? (n.up_quality + "").split("|") : [],
                        l = this.getEquipData1(c, o, a, s, r);
                    e = this.selList.length < c.length + p.length;
                    if (l) for (var d = 0; d < l.length; d++) this.setCanClickNodeList.push(l[d]);
                }
                e ? this.checkCanClick() : this.setAllNull();
            };
            e.prototype.getTypeQuality = function () {
                return [];
            };
            e.prototype.updateMerageData = function (t, e) {
                void 0 === e && (e = "");
                for (
                    var o = t.split("|"),
                        a = CacheDataManager.getCostumeup(),
                        i = CacheDataManager.getCostume(),
                        n = GameDataValue.getAllSelfEquip(),
                        r = [],
                        s = [],
                        c = [],
                        p = 0;
                    p < this.selList.length;
                    p++
                ) {
                    var l = n[this.selList[p]];
                    r.push(l.id);
                    c.push(l.id);
                    s.push(l.lv);
                }
                var d = 1;
                for (p = 0; p < 3; p++) {
                    var u = o[p] || c[p],
                        h = "_viewCurNode" + (p + 1);
                    if (u) {
                        this[h].active = !0;
                        var f = this[h].$BoxItem,
                            y = (_ = r.indexOf(u)) >= 0,
                            v = i[(l = a[u]).costume_id];
                        f.resetView();
                        d = v.type;
                        SpriteView.setTaskSprite(f.iconSprite, CacheDataManager.getEquipCostumeUpToIcon(l));
                        f.setQualityData(l.quality);
                        f.levelLab.string = "lv:" + (s[_] || 1);
                        f.nodeKindItem.setTypeKind(v.type, l.quality);
                        if (y) {
                            r.splice(_, 1);
                            s.splice(_, 1);
                            f.drakView.active = !1;
                        } else f.drakView.active = !0;
                    } else this[h].active = !1;
                }
                var g = e ? e.split("|") : [],
                    m = g.length;
                if (m > 0)
                    for (p = 0; p < m; p++) {
                        var _ = c.length + p + 1;
                        if (c.length < g.length + o.length && this[(h = "_viewCurNode" + _)]) {
                            this[h].active = !0;
                            (f = this[h].$BoxItem).resetView();
                            var C = parseInt(g[p]);
                            SpriteView.setTypeIcon(d, f.iconSprite);
                            f.setQualityData(C);
                            f.levelLab.string = "lv:" + (s[_] || 1);
                            f.nodeKindItem.setTypeKind(d, C);
                            f.drakView.active = !0;
                        }
                    }
            };
            e.prototype.setMerageData = function (t) {
                if (t && this.selList.length > 0) {
                    var e = this.selList[0],
                        o = GameDataValue.getEquipData(e).id,
                        a = CacheDataManager.getCostumeup(),
                        i = CacheDataManager.getCostume(),
                        n = this._boxItem.$BoxItem,
                        r = a[this.merageId],
                        s = i[r.costume_id],
                        c = a[o];
                    if (r) {
                        this.updateMerageData(r.up_costume + "", r.up_quality ? r.up_quality + "" : "");
                        n.resetView();
                        SpriteView.setTaskSprite(n.iconSprite, CacheDataManager.getEquipCostumeUpToIcon(r));
                        n.setQualityData(r.quality);
                        SpriteView.setQualityBgLineColor(r.quality, this._newTip);
                        n.levelLab.string = "lv:1";
                        n.nodeKindItem.setTypeKind(s.type, r.quality);
                        this._merageNameLab.$Label.string = CacheDataManager.getEquipName(t);
                        var p = CacheDataManager.getQualityLevelIndexAdd(r.quality, "1"),
                            l = CacheDataManager.getQualityLevelIndexAdd(c.quality, "1") + "%",
                            d = p + "%";
                        this._allPro1.$Label.string = l;
                        this._allPro2.$Label.string = d;
                        for (var u = 0; u < 4; u++) {
                            var h = "unlock" + (u + 1);
                            if (r.quality == s[h]) {
                                var f = "value" + (u + 1) + "_desc",
                                    y = "value" + (u + 1);
                                this._newItemBgCom.$BgItemColorCom.setColor(s[h]);
                                var v = "";
                                if (3 == u) {
                                    var g = s[y];
                                    v =
                                        "" +
                                        CacheDataManager.getQualityLevelAdd(r.quality, 1) *
                                            (this.getLastValue(g + "") / 100);
                                }
                                this._newTip.$Label.string = CacheDataManager.getLang(s[f]);
                                this._newTip2.$Label.string = "" != v ? v + "%" : "+" + this.getLastValue(s[y]) + "%";
                                break;
                            }
                        }
                    } else this.updateMerageData("");
                } else this.updateMerageData("");
            };
            e.prototype.getLastValue = function (t) {
                var e = t.split("_");
                return parseFloat((e[e.length - 1] || 0) + "");
            };
            e.prototype.getMerageKey = function (t) {
                var e = "",
                    o = GameDataValue.getAllSelfEquip()[t];
                if (o) {
                    var a = CacheDataManager.getCostumeup(),
                        i = CacheDataManager.getCostume(),
                        n = o.id,
                        r = a[n],
                        s = i[r.costume_id];
                    e = this.getNextEquipKey(s.type, r.quality + 1, n[n.length - 1], a, i);
                }
                return e;
            };
            e.prototype.getNextEquipKey = function (t, e, o, a, i) {
                var n = "";
                for (var r in a) {
                    var s = i[a[r].costume_id];
                    if (a[r].quality == e && s.type == t && r[r.length - 1] == o) {
                        n = r;
                        break;
                    }
                }
                return n;
            };
            e.prototype.getQualityList = function (t) {
                var e = [];
                if (t) for (var o = t.split("|"), a = 0; a < o.length; a++) e.push(parseInt(o[a]));
                return e;
            };
            e.prototype._onReturnZBTouchEnd = function () {
                c.default.open(s.UIID.UIZhuanBei);
                this.closeUI();
            };
            e.prototype.getEquipData1 = function (t, e, o, a, i) {
                for (var n = [], r = [], s = 0; s < t.length; s++) r.push(t[s]);
                for (var c in e) {
                    var p = r.indexOf(e[c].id);
                    this.selList.indexOf(e[c].indexId) >= 0 && p >= 0 && r.splice(p, 1);
                }
                var l = CacheDataManager.getCostume();
                for (var c in e) {
                    var d = o[e[c].id],
                        u = l[d.costume_id].type;
                    a.indexOf(d.quality) >= 0 && i == u && n.indexOf(e[c].indexId) < 0 && n.push(e[c].indexId);
                }
                for (var c in e) r.indexOf(e[c].id) >= 0 && n.indexOf(e[c].indexId) < 0 && n.push(e[c].indexId);
                for (s = 0; s < this.selList.length; s++) n.indexOf(this.selList[s]) <= 0 && n.push(this.selList[s]);
                return n;
            };
            e.prototype.setBtnRend = function (t) {
                for (var e = this._merageBtn.getComponentsInChildren(cc.RenderComponent), o = 0; o < e.length; o++)
                    CacheDataManager.setSpriteMat(e[o], t);
            };
            e.prototype.setAllNull = function () {
                this.canClick = !0;
                EVUIEffView.emit(EVUIEffView.setViewBool, this.tag, this.selList, !1);
                this.setBtnRend(!0);
            };
            e.prototype.checkCanClick = function () {
                this.canClick = !1;
                this.setBtnRend(!1);
                EVUIEffView.emit(EVUIEffView.setViewBool, this.tag, this.setCanClickNodeList, !1);
            };
            e.prototype.onCloseStart = function () {
                CacheDataManager.updateEquip = !0;
                EVUIEffView.offTarget(this);
            };
            e.prototype._onOpenRuleTouchEnd = function () {
                c.default.open(s.UIID.UIGameRule);
            };
            e.prototype._onTab1TouchEnd = function () {
                this.selSkillItem = 1;
                this.updateView();
            };
            e.prototype._onTab2TouchEnd = function () {
                this.selSkillItem = 2;
                this.updateView();
            };
            e.prototype._onTab3TouchEnd = function () {
                this.selSkillItem = 3;
                this.updateView();
            };
            e.prototype.updateView = function () {
                var t = GameDataValue.getAllSelfEquip();
                this.tempViewList.length = 0;
                for (var e in t) t[e] && this.tempViewList.push(t[e]);
                this.updateLevelData(this.tempViewList);
                if (this.selList.length > 0 && this.merageId) {
                    this.setData1();
                    this.setCheckList(this.merageId);
                    this.setMerageData(this.merageId);
                } else {
                    this.setData2();
                    this.setCanClickNodeList.length = 0;
                    EVUIEffView.emit(EVUIEffView.setViewBool, this.tag, this.setCanClickNodeList, !0);
                }
                EVUIEffView.emit(EVUIEffView.viewBoxMask, this.tag, this.selList, !0);
            };
            e.prototype.setData1 = function () {
                this.setNodeView(!1);
            };
            e.prototype.setData2 = function () {
                this.setNodeView(!0);
            };
            e.prototype.setNodeView = function (t) {
                this._viewNode1.active = t;
                this._viewNode2.active = !t;
            };
            e.prototype.updateLevelData = function (t) {
                if (t.length > 0) {
                    for (
                        var e = t, o = 1, a = {}, i = CacheDataManager.getCostumeup(), n = e.length;
                        n < this.looperNode.length;
                        n++
                    )
                        this.looperNode[n].active = !1;
                    for (n = 0; n < e.length; n++) {
                        if (!this.looperNode[n]) {
                            var r = QLooperNode.getNode(QLooperNode.tag_boxItem);
                            r.parent = this._allContent;
                            r.setPosition(cc.Vec2.ZERO);
                            this.looperNode.push(r);
                        }
                        var s = i[e[n].id].costume_id;
                        if (!a[s]) {
                            a[s] = o;
                            o++;
                        }
                        this.viewItem(this.looperNode[n], e[n], n, a[s]);
                    }
                } else for (n = 0; n < this.looperNode.length; n++) this.looperNode[n].active = !1;
            };
            e.prototype.viewItem = function (t, e, o, a) {
                t.active = !0;
                var i = t.getComponent(p.default);
                if (i) {
                    var n = CacheDataManager.getCostumeup();
                    if (n[e.id]) {
                        var r = CacheDataManager.getCostume()[n[e.id].costume_id],
                            s = r.type;
                        i.id = e.indexId;
                        i.tag = this.tag;
                        i.nodeKindItem.setTypeKind(s, n[e.id].quality);
                        i.typeIndex = s;
                        i.levelLab.string = "lv:" + e.lv;
                        i.resetView();
                        if (GameDataValue.getWearEquip(r.type) == e.indexId) {
                            t.zIndex = 0;
                            i.openWear();
                        } else if (this.merageData[e.id]) {
                            t.zIndex = 550 - 20 * n[e.id].quality - a;
                            i.openRed();
                        } else t.zIndex = 900 - 20 * n[e.id].quality - a;
                        SpriteView.setTaskSprite(i.iconSprite, CacheDataManager.getEquipCostumeUpToIcon(n[e.id]));
                        i.setQualityData(n[e.id].quality);
                    }
                }
            };
            e.prototype._onMerageBtnTouchEnd = function () {
                var t = this;
                if (this.canClick) {
                    for (
                        var e = this.merageId, o = [], a = 0, i = CacheDataManager.getCostumeup(), n = 0;
                        n < this.selList.length;
                        n++
                    ) {
                        var r = GameDataValue.getEquipData(this.selList[n]).lv,
                            p = GameDataValue.removeEquip(this.selList[n]),
                            l = i[p];
                        a += CacheDataManager.getCostumeLvData(l.quality, r).back_diamond || 0;
                        o.push(p);
                    }
                    this.selList.length = 0;
                    GameDataValue.addEquip(this.merageId);
                    c.default.open(s.UIID.UIMergeAnimal, {merageId: e, list: o, addCost: a});
                    this.scheduleOnce(function () {
                        t.updateViewMergeData();
                        t.updateView();
                        CacheDataManager.updateEquip = !0;
                        CacheDataManager.isUpdateNextSave = !0;
                    });
                }
            };
            return n([d], e);
        })(r.default));
o.default = u;
